﻿using System.Collections.Generic;
using Inovout.Gis.Geometry;
using System.Collections.Specialized;
using System;

namespace Inovout.Gis
{
    public abstract class RepositoryFactory
    {
        #region DomainRepository
        private static List<RepositoryFactory> repositoryFactionaries = new List<RepositoryFactory>();
        public static void Regiester(params RepositoryFactory[] gisRepositoryFactionaries)
        {
            repositoryFactionaries.AddRange(gisRepositoryFactionaries);
        }
        public static IGisRepository GetRepository(IGeometryInfo geometry)
        {
            //基于Gis的业务数据持久化
            foreach (var repositoryFactory in repositoryFactionaries)
            {
                IGisRepository repository = repositoryFactory.CreateRepository(geometry);
                if (repository != null)
                {
                    return repository;
                }
            }
            throw new NotImplementedException(geometry.GetType().Name);
        }
        public abstract IGisRepository CreateRepository(IGeometryInfo geometry);
        #endregion

        #region GisInfoRepository
        public static IGisInfoRepositoryFactory GisInfoRepositoryFactory;
        public static IGisInfoRepository GetGisInfoRepository(NameValueCollection datasourceConfig)
        {
            //因为Geometry都是必须先获取到Layer信息
            return GisInfoRepositoryFactory.CreateGisInfoRepository(datasourceConfig);
        }
        #endregion
    }
}
